<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
<title>title</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script type="text/javascript">
	function checkValue(args) {
		var title=document.getElementById("title").value;
		var content=document.getElementById("content").value;
		if(title==""){
			alert("제목을 입력하세요.");
			return;
		}else if(content==""){
			alert("내용을 입력하세요.");
			return;
		}
		document.updateForm.submit();
	}
	
	function cancelWriting() {
		if(confirm("취소하시겠습니까?"))
			history.back();
	}
	
	var xhr;
	function startRequest(){
		xhr = new XMLHttpRequest();
		xhr.onreadystatechange=callback;
		xhr.open("get","/OffTheRecord/deleteFile.action?boardId=${requestScope.map.bvo.boardId}",true);
		xhr.send(null);
	}
	function callback(){
		if(xhr.readyState==4){
			if(xhr.status==200){
				document.getElementById("uploadView").innerHTML=
					"파일 업로드<input type='file' name='uploadFile' class='form-control'>";
			}
		}
	}
</script>
</head>
<body>
<c:import url="../common/top.jsp"></c:import>
<div class="container" style="margin: 30px;"></div>

<div class="container">
<div class="row">
<div class="col-sm-2 col-md-2- col-lg-2"></div>
<!--  -->
<div class="col-xs-12 col-sm-8 col-md-8- col-lg-8">
	<hr color="lightgray">
<div style="height: 10px; background-color: white;"></div>
	  <font style="font-weight: bold; font-size: 20px;">자유게시판 글쓰기</font><p><p>

게시판 수정하기<br>
<c:if test="${ sessionScope.userVo!=null}">
<form action="/OffTheRecord/updateBoard.action" name="updateForm" method="post" enctype="multipart/form-data">
<input type="hidden" name="boardId" value="${requestScope.map.bvo.boardId}">
제목 : <input type="text" class="form-control" value="${requestScope.map.bvo.boardTitle}" id="title" name="updateTitle"><br>
내용 : <textarea class="form-control" rows="15" cols="40" id="content" name="updateContent">${requestScope.map.bvo.boardContent}</textarea><br>
<span id="uploadView">
	<c:choose>
		<c:when test="${requestScope.map.fvo.fileName=='No file.' || requestScope.map.fvo.fileName==null }">
			파일 업로드<input type="file" name="uploadFile" class="form-control">
		</c:when>
		<c:otherwise>
			<div align="center">
				${requestScope.map.fvo.fileName}<a href="javascript:startRequest()" class="btn btn-default btn-sm">삭 제</a>
			</div>
		</c:otherwise>
	</c:choose>				
</span>
<div align="center"><br>
<input type="button" value="확인" onclick="checkValue()" class="btn btn-default btn-sm">
<input type="button" value="취소" onclick="cancelWriting()" class="btn btn-default btn-sm">
</div>
</c:if>
</form>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</body>
</html>